home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Chat / server / FriendsServer.class (.txt) next >
Encoding:
Java Class File  |  2001-10-30  |  3.1 KB  |  137 lines

  1. import java.net.ServerSocket;
  2. import java.net.Socket;
  3. import java.util.Vector;
  4.  
  5. public class FriendsServer {
  6.    Socket socket;
  7.    // $FF: renamed from: ss java.net.ServerSocket
  8.    ServerSocket field_0;
  9.    Vector thread;
  10.    int priority = 2;
  11.    String prefix = "***";
  12.    boolean debug = false;
  13.    String topic;
  14.    String topicAuthor;
  15.  
  16.    public static void main(String[] var0) {
  17.       int var1 = 0;
  18.       if (var0.length != 0) {
  19.          try {
  20.             var1 = Integer.parseInt(var0[0]);
  21.          } catch (Exception var2) {
  22.             var1 = 5554;
  23.          }
  24.       } else {
  25.          var1 = 5554;
  26.       }
  27.  
  28.       new FriendsServer(var1);
  29.    }
  30.  
  31.    FriendsServer(int var1) {
  32.       try {
  33.          this.field_0 = new ServerSocket(var1);
  34.       } catch (Exception var3) {
  35.          System.out.println(var3);
  36.       }
  37.  
  38.       this.init();
  39.    }
  40.  
  41.    public void init() {
  42.       this.thread = new Vector();
  43.  
  44.       try {
  45.          while(true) {
  46.             if (this.debug) {
  47.                System.out.println("socket waiting...");
  48.             }
  49.  
  50.             this.socket = this.field_0.accept();
  51.             if (this.debug) {
  52.                System.out.println("accept a connectionon port  " + Integer.toString(5554));
  53.             }
  54.  
  55.             int var1 = this.thread.size();
  56.             FriendsServer$RecThread var2 = new FriendsServer$RecThread(this, this.socket, var1, this);
  57.             ((Thread)var2).setPriority(this.priority);
  58.             ((Thread)var2).start();
  59.             this.thread.addElement(var2);
  60.          }
  61.       } catch (Exception var3) {
  62.          System.out.println(var3);
  63.       }
  64.    }
  65.  
  66.    public void sendAll(int var1, String var2) {
  67.       for(int var3 = 0; var3 < this.thread.size(); ++var3) {
  68.          if (var3 != var1) {
  69.             ((FriendsServer$RecThread)this.thread.elementAt(var3)).send(var2);
  70.          }
  71.       }
  72.  
  73.    }
  74.  
  75.    public void sendAll(String var1) {
  76.       for(int var2 = 0; var2 < this.thread.size(); ++var2) {
  77.          ((FriendsServer$RecThread)this.thread.elementAt(var2)).send(var1);
  78.       }
  79.  
  80.    }
  81.  
  82.    public void sendOne(int var1, String var2) {
  83.       ((FriendsServer$RecThread)this.thread.elementAt(var1)).send(var2);
  84.    }
  85.  
  86.    public int giveId(String var1) {
  87.       for(int var2 = 0; var2 < this.thread.size(); ++var2) {
  88.          if (((FriendsServer$RecThread)this.thread.elementAt(var2)).nick.equals(var1)) {
  89.             return var2;
  90.          }
  91.       }
  92.  
  93.       return -1;
  94.    }
  95.  
  96.    public void stop(int var1, int var2) {
  97.       if (this.debug) {
  98.          System.out.println("thread " + Integer.toString(var1) + " libere");
  99.       }
  100.  
  101.       FriendsServer$RecThread var3 = (FriendsServer$RecThread)this.thread.elementAt(var1);
  102.       if (var3.is_nick) {
  103.          if (var2 == 0) {
  104.             this.sendAll(var1, var3.nick + " PART @ " + var3.arg[3] + "\n");
  105.          } else {
  106.             this.sendAll(var1, var3.nick + " PART @ " + "crash !" + "\n");
  107.          }
  108.       }
  109.  
  110.       this.thread.removeElementAt(var1);
  111.       if (var3 != null) {
  112.          ((Thread)var3).stop();
  113.       }
  114.  
  115.    }
  116.  
  117.    public boolean isNick(String var1) {
  118.       for(int var2 = 0; var2 < this.thread.size(); ++var2) {
  119.          if (((FriendsServer$RecThread)this.thread.elementAt(var2)).nick.equals(var1)) {
  120.             return true;
  121.          }
  122.       }
  123.  
  124.       return false;
  125.    }
  126.  
  127.    public String giveNicks() {
  128.       String var1 = new String();
  129.  
  130.       for(int var2 = 0; var2 < this.thread.size(); ++var2) {
  131.          var1 = var1 + " " + ((FriendsServer$RecThread)this.thread.elementAt(var2)).nick;
  132.       }
  133.  
  134.       return var1.trim();
  135.    }
  136. }
  137.